﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<%@include file="/common/javascript.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml" id="teacherForm">
<head>
    <title>学生设定</title>
    <script type="text/javascript">
    var mainform;
    var viewType = "${viewType}";

    $(function (){
    	$("#date").ligerDateEditor();
    	$("#dateExpire").ligerDateEditor();
    	
        mainform=$("#mainform");
        
        mainform.ligerForm();
        
        //如果是修改视图,主键不可编辑
        if(viewType=="modify"){
        	 $("#stuId").attr("readonly", "readonly").removeAttr("validate");
        }
        
        //如果是详细试图,所有字段不可编辑
        if(viewType=="detail"){
        	$("input,select,textarea",mainform).attr("readonly", "readonly");
        }else{
            $.metadata.setType("attr", "validate");
            LG.validate(mainform);
        }
        
        $.validator.addMethod('sexChecker', function(value) {
        	if (value != -1)
    			return true;
    		else  
    			return false;
            }, '请选择性别'); 
        
        // 给性别赋值
		var sSex="${command.stuSex}";        
        if(sSex=='0'){
        	$("#stuSex").val(0);
        }else if(sSex=='1'){
        	$("#stuSex").val(1);
        }else{
        	$("#stuSex").val(-1);
        }
        
        //渲染按钮
        LG.setFormDefaultBtn(cancel,viewType=="detail" ? null : save);
        
        if($("#clsId").val()!='-1'){
        	$("#clsId").attr("disabled",false);
        }else{
        	$("#clsId").attr("disabled","disabled");
        }
        
        if($("#gradeId").val()!='-1'){
        	$("#gradeId").attr("disabled",false);
        }else{
        	$("#gradeId").attr("disabled","disabled");
        }
        
        if($("#gradeId").val()!='-1' && $("#classId").val()!='-1'){
        	resetOptions($("#deptId").find("option:selected").text(),
					$("#gradeId").find("option:selected").text());
        }
        
        //调整form-bar
        $(".form-bar").css("width","630px");
    });
    
    function resetOptions(t1,t2){
    	document.getElementById('clsId').options.length = 0;  //清空原有的option 
    	var str="<option value='-1'>请选择</option>";  
    	jQuery.each(${clses}, function(i,item){
    		if(t1==item.deptTitle && t2==item.gradeTitle){
    			if("${command.clsId}"==item.clsId){
    				str+="<option value='"+item.clsId+"' selected='selected'>"+item.clsTitle+"</option>"
    			}else{
    				str+="<option value='"+item.clsId+"'>"+item.clsTitle+"</option>"
    			}
    		}
    	});   
		$("#clsId").html(str);
    	
    }
   
    function save(){
    	if($("#stuSex").val()=='-1'){
    		LG.showError('请选择性别');
    	}else{
    		LG.submitForm(mainform, function (result) {
            	if(typeof(result)=="string"){
            		result=eval("("+result+")");
            	}
                if (!result.success) {
                    LG.showError('错误:' + result.message);
                }
                else { 
                    LG.showSuccess('保存成功', function () { 
                       LG.callParent("stuList");
                    });
                }
            });
    	}
    }
    function cancel(){
        var win = window.parent || window;
        if(win.dialog){
        	win.dialog.close();
        }
    }
    
    function onGradeChange(){
		if($("#gradeId").val()!='-1'){
			if($("#deptId").val()!='-1'){
				$("#clsId").attr("disabled",false);
				resetOptions($("#deptId").find("option:selected").text()
						,$("#gradeId").find("option:selected").text());
	    	}
    	}
    }
    
    function onDeptChange(){
    	if($("#deptId").val()!='-1'){
    		$("#gradeId").attr("disabled",false);
			if($("#gradeId").val()!='-1'){
				$("#clsId").attr("disabled",false);
				resetOptions($("#deptId").find("option:selected").text(),
						$("#gradeId").find("option:selected").text());
	    	}
    	}
    }
 </script>
</head>

<body>
    <form name="mainform" method="post"  id="mainform" action="${ctx }/qso/student/save">
        <input type="hidden" name="viewType" value="${viewType}"/>
        <table cellpadding="0" cellspacing="0" class="l-table-edit" style="width: 95%; margin-top:10px; margin-left:15px;">
            <tr>
                <td align="right" class="l-table-edit-td" style="width:15%;">学生编号:</td>
                <td align="left" class="l-table-edit-td" style="width:35%;">
                	${command.stuId}
                	<input name="stuId" type="hidden" id="stuId" value="${command.stuId}" ltype="text" />
                </td>
                <td align="right" class="l-table-edit-td" style="width:15%;">学生姓名:</td>
                <td align="left" class="l-table-edit-td" style="width:35%;">
                	<input name="stuName" type="text" id="stuName" value="${command.stuName}" ltype="text" maxlength="10" validate="{required:true, notnull:true}" nullText="不能为空" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if>/>
                </td>
            </tr>
            <tr>               
                <td align="right" class="l-table-edit-td">学生性别:</td>
                <td align="left" class="l-table-edit-td" >
					<select id="stuSex" name="stuSex" validate="{required:true, sexChecker:true}" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if>>
						<option value="-1">请选择</option>
						<option value="0">男</option>
						<option value="1">女</option>
					</select>
                </td>
                
                <td align="right" class="l-table-edit-td">学生电话:</td>
                <td align="left" class="l-table-edit-td" >
                	<input name="stuTel" type="text" id="stuTel" value="${command.stuTel}" maxlength="15" validate="{required:true, digits:true, notnull:true}" nullText="不能为空" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if>/>
                </td>
            </tr>
            <tr>
                <td align="right" class="l-table-edit-td">学生邮箱:</td>
                <td align="left" class="l-table-edit-td" >
                	<input name="stuMail" type="text" id="stuMail" value="${command.stuMail}" validate="{required:true, notnull:true, email:true}" nullText="不能为空" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if>/>
                </td>
                <td align="right" class="l-table-edit-td">登录账号:</td>
                <td align="left" class="l-table-edit-td" >
                	<c:if test="${viewType=='add'}">
                		<input name="stuUserId" type="text" id="stuUserId" maxlength="30" value="${command.stuUserId}" validate="{required:true, notnull:true}" nullText="不能为空" />
                	</c:if>
                	<c:if test="${viewType!='add'}">
                		${command.stuUserId}
                		<input name="stuUserId" type="hidden" id="stuUserId" value="${command.stuUserId}" validate="{required:true}"/>
                	</c:if>
                </td>		
            </tr>
            <tr>
            	<td align="right" class="l-table-edit-td" valign="top">所属班级:</td>
				<td align="left" class="l-table-edit-td" colspan="3">
				<c:if test="${viewType!='detail'}">
				<select style="width:135px;" name="deptId" id="deptId" onchange="onDeptChange()">
					<option value="-1">请选择科系</option>
					<c:forEach items="${depts}" var ="dep">
						<c:choose>
							<c:when test="${cla.dept.id eq dep.id }">
								<option value="${dep.id}" selected="selected">${dep.title}</option>
							</c:when>
							<c:otherwise>
								<option value="${dep.id}">${dep.title}</option>
							</c:otherwise>
						</c:choose>
					</c:forEach>
				</select>
				<select style="width:135px;" id="gradeId" name="gradeId" onchange="onGradeChange()">
					<option value="-1">请选择年级</option>
					<c:forEach items="${grades}" var ="gra">
						<c:choose>
							<c:when test="${cla.grade.gradeId eq gra.gradeId }">
								<option value="${gra.gradeId}" selected="selected">${gra.gradeTitle}</option>
							</c:when>
							<c:otherwise>
								<option value="${gra.gradeId}">${gra.gradeTitle}</option>
							</c:otherwise>
						</c:choose>
					</c:forEach>
				</select>
				<select style="width:200px;" name="clsId" id="clsId" ltype="select" validate="{required:true}">
                	 	<option value="-1">请选择班级</option>
                	 	<c:forEach items="${clses}" var="cls">
                	 		<c:choose>
                	 			<c:when test="${command.clsId eq cls.clsId}">
                	 				<option value="${cls.clsId}" selected="selected">${cls.clsTitle}</option>
                	 			</c:when>
                	 			<c:otherwise>
                	 				<option value="${cls.clsId}">${cls.clsTitle}</option>
                	 			</c:otherwise>
                	 		</c:choose>
                	 	</c:forEach>
                </select> 
                </c:if>
                <c:if test="${viewType=='detail'}">
                <select style="width:135px;" disabled="disabled">
					<option selected="selected">${cla.dept.title}</option>
				</select>
				<select style="width:135px;" disabled="disabled">
					<option selected="selected">${cla.grade.gradeTitle}</option>
				</select>
				<select style="width:200px;" disabled="disabled">
 					<option selected="selected">${cla.clsTitle}</option>
                </select> 
                </c:if>
				</td>
			</tr>
			<tr>
				<td align="right" class="l-table-edit-td">过期日期:</td>
				<td align="left" class="l-table-edit-td">
				<c:if test="${viewType!='detail'}">
					<input name="dateExpire" type="text" id="dateExpire" value="${command.dateExpire}" ltype="date" format="yyyy-MM-dd" validate="{required:true}"/>
				</c:if>
				<c:if test="${viewType=='detail'}">
					<input type="text"value="${command.dateExpire}" disabled="disabled" />
				</c:if>
				</td>
			</tr>
            <tr>
                <td align="right" class="l-table-edit-td" valign="top">备注:</td>
                <td align="left" class="l-table-edit-td" colspan="4"> 
                <textarea cols="100" rows="3" class="l-textarea" id="remark" name="remark" style="width:470px"  <c:if test="${viewType=='detail'}">disabled="disabled"</c:if>>${command.remark}</textarea>
                </td> <td align="left"></td>
           </tr>
        </table>       
    </form>
</body>
</html>
